/*
 *@Author: 张楚
 *@Date: 2022-02-09 18:06:58
 *@Description: 模仿DropdownButton
*/
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

class SmartDialogUntils {
  static void attachImitate() {
    //模仿DropdownButton
    imitateDialog(BuildContext context) {
      var list = ['小呆呆', '小菲菲', '小猪猪'];
      SmartDialog.showAttach(
        targetContext: context,
        isPenetrateTemp: true,
        widget: Container(
          margin: EdgeInsets.all(10),
          decoration: BoxDecoration(
            boxShadow: [
              BoxShadow(color: Colors.black12, blurRadius: 8, spreadRadius: 0.2)
            ],
          ),
          child: Column(
            children: List.generate(list.length, (index) {
              return Material(
                color: Colors.white,
                child: InkWell(
                  onTap: () {
                    SmartDialog.dismiss();
                    print(list[index]);
                  },
                  child: Container(
                    height: 50,
                    width: 100,
                    alignment: Alignment.center,
                    child: Text('${list[index]}'),
                  ),
                ),
              );
            }),
          ),
        ),
      );
    }

    //imitate widget
    dropdownButton({String title = 'Dropdown'}) {
      return DropdownButton<String>(
        value: '1',
        items: [
          DropdownMenuItem(value: '1', child: Text('$title：小呆呆')),
          DropdownMenuItem(value: '2', child: Text('小菲菲')),
          DropdownMenuItem(value: '3', child: Text('小猪猪'))
        ],
        onChanged: (value) {},
      );
    }

    imitateDropdownButton() {
      return Builder(builder: (context) {
        return Stack(children: [
          dropdownButton(title: 'Attach'),
          InkWell(
            onTap: () => imitateDialog(context),
            child: Container(height: 50, width: 140, color: Colors.transparent),
          )
        ]);
      });
    }

    SmartDialog.show(
      isLoadingTemp: false,
      widget: Container(
        width: 300,
        height: 200,
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: 20),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(20),
          color: Colors.white,
        ),
        child: MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Column(
            // mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [dropdownButton(), imitateDropdownButton()],
          ),
        ),
      ),
    );
  }
}
